package com.baofu.paycore.biz.engine.generator.impl;

import com.baofu.paycore.biz.engine.command.Command;
import com.baofu.paycore.biz.engine.generator.CommandGenerator;
import com.baofu.paycore.biz.paycore.converter.CommandConverter;
import com.baofu.paycore.manager.model.PayBO;
import com.baofu.paycore.manager.model.SubPayBO;
import com.baofu.paycore.service.facade.enums.PayToolRouteEnum;
import com.google.common.base.Strings;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 支付指令生成
 *
 * <p/>
 *      1、生成命令
 * </p>
 * User: LZQ Date: 2016/04/21  Version: 1.0
 */
@Service
public class PayCommandGenerator implements CommandGenerator<PayBO> {

    /**
     * 生成指令
     *
     * @param payBO        订单模型
     * @return             命令列表
     */
    @Override
    public List<Command> generatorCommands(PayBO payBO) {

        List<Command> list = new ArrayList<>();

        List<SubPayBO> payerFundDetails = payBO.getSubPayList();
        for (SubPayBO subPayBO : payerFundDetails){
            if (PayToolRouteEnum.ACCOUNT_TRANSFER_ROUTE.containsPayTool(subPayBO.getPayToolType())){

                list.add(CommandConverter.balanceCommandConverter(subPayBO, payBO));

            } else if (PayToolRouteEnum.CLEAR_WEBPAY_ROUTE.containsPayTool(subPayBO.getPayToolType())){
                if(Strings.isNullOrEmpty(payBO.getSmsCode())){
                    list.add(CommandConverter.bankCommandConverter(subPayBO, payBO));
                }else{
                    list.add(CommandConverter.bankConfirmCommandConverter(subPayBO, payBO));
                }
            }
        }
        return list;
    }
}